﻿namespace WMS6.Web.OrderManagement
{
    using System;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using WMS6.Web;
    using WMS6.Web.UserControls;

    public class SalesOrderQuery : BasePage
    {
        protected Button btnExport;
        protected Button btnList;
        protected Button btnNew;
        protected Button btnSearch;
        protected DropDownList ddlCreatedByOper;
        protected DropDownList ddlCustomerIDOper;
        protected DropDownList ddlExpectArrivalDateOper;
        protected DropDownList ddlExternOrderIDOper;
        protected DropDownList ddlOwnerIDOper;
        protected DropDownList ddlSoDateOper;
        protected DropDownList ddlSoIDOper;
        protected DropDownList ddlSoTypeOper;
        protected DropDownList ddlStatusOper;
        protected HtmlForm F3020;
        protected HtmlInputHidden hdnActionID;
        protected HtmlInputHidden hdncalendarFlag;
        protected HtmlInputHidden hdnDataFormat;
        protected HtmlImage img1;
        protected HtmlImage img3;
        protected Label lblCreatedBy;
        protected Label lblCustomerID;
        protected Label lblExpectArrivalDate;
        protected Label lblExternOrderID;
        protected Label lblOwnerID;
        protected Label lblSalesOrder;
        protected Label lblSoDate;
        protected Label lblSoID;
        protected Label lblSoType;
        protected Label lblStatus;
        protected MultipleSelectControl MSCSoType;
        protected MultipleSelectControl MSCStatus;
        protected HtmlLink mycss;
        protected ScriptManager ScriptManager1;
        protected TextBox txtCreatedBy;
        protected TextBox txtCustomerID;
        protected TextBox txtExpectArrivalDate;
        protected TextBox txtExpectArrivalDate2;
        protected TextBox txtExternOrderID;
        protected TextBox txtOwnerID;
        protected TextBox txtSoDate;
        protected TextBox txtSoDate2;
        protected TextBox txtSoID;

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            base.Server.Transfer(string.Format("SalesOrderList.aspx?action={0}", base.UrlEncode(this.hdnActionID.Value.Trim())), false);
        }

        private void LoadData()
        {
            if (!string.IsNullOrEmpty(base.Request.QueryString["action"]))
            {
                this.btnNew.Visible = false;
                this.btnExport.Visible = false;
                this.hdnActionID.Value = base.Request.QueryString["action"].ToString();
            }
        }

        private void LoadDLL()
        {
            base.InitQueryDDL(this.ddlSoIDOper, 0);
            base.InitQueryDDL(this.ddlOwnerIDOper, 0);
            base.InitQueryDDL(this.ddlCustomerIDOper, 0);
            base.InitQueryDDL(this.ddlSoDateOper, 1);
            base.InitQueryDDL(this.ddlExpectArrivalDateOper, 1);
            base.InitQueryDDL(this.ddlSoTypeOper, 0);
            base.InitQueryDDL(this.ddlExternOrderIDOper, 0);
            base.InitQueryDDL(this.ddlStatusOper, 0);
            base.InitQueryDDL(this.ddlCreatedByOper, 0);
            base.BindData2DDLBySysCode(this.MSCStatus, "OrderStatus");
            this.ddlStatusOper.SelectedValue = "One Of";
            base.BindData2DDLBySysCode(this.MSCSoType, "SalesOrderType");
            this.ddlSoTypeOper.SelectedValue = "One Of";
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!base.IsPostBack)
            {
                base.InitPage(this.Page);
                this.LoadDLL();
                this.LoadData();
                if (base.UserInfo.IsWhUser.ToUpper() != "Y")
                {
                    this.txtCreatedBy.Text = base.UserInfo.UserID;
                    this.txtCreatedBy.Enabled = false;
                    this.ddlCreatedByOper.SelectedValue = "Same As";
                    this.ddlCreatedByOper.Enabled = false;
                }
            }
        }

        public string CreatedBy
        {
            get
            {
                if (!string.IsNullOrEmpty(this.txtCreatedBy.Text.Trim()))
                {
                    return base.GetParamsString(this.txtCreatedBy.Text.Trim(), this.ddlCreatedByOper.SelectedValue);
                }
                return "";
            }
        }

        public string CustomerID
        {
            get
            {
                if (!string.IsNullOrEmpty(this.txtCustomerID.Text.Trim()))
                {
                    return base.GetParamsString(this.txtCustomerID.Text.Trim(), this.ddlCustomerIDOper.SelectedValue);
                }
                return "";
            }
        }

        public string ExpectArrivalDate
        {
            get
            {
                if (!string.IsNullOrEmpty(this.txtExpectArrivalDate.Text.Trim()))
                {
                    return base.GetParamsString(this.txtExpectArrivalDate.Text.Trim(), this.ddlExpectArrivalDateOper.SelectedValue, this.txtExpectArrivalDate2.Text.Trim(), "ExpectArrivalDate");
                }
                return "";
            }
        }

        public string ExternalOrderID
        {
            get
            {
                if (!string.IsNullOrEmpty(this.txtExternOrderID.Text.Trim()))
                {
                    return base.GetParamsString(this.txtExternOrderID.Text.Trim(), this.ddlExternOrderIDOper.SelectedValue);
                }
                return "";
            }
        }

        public string OrderStatus
        {
            get
            {
                if (!string.IsNullOrEmpty(this.MSCStatus.ReturnValue))
                {
                    return base.GetParamsString(this.MSCStatus.ReturnValue, this.ddlStatusOper.SelectedValue);
                }
                return "";
            }
        }

        public string OrderType
        {
            get
            {
                if (!string.IsNullOrEmpty(this.MSCSoType.ReturnValue))
                {
                    return base.GetParamsString(this.MSCSoType.ReturnValue, this.ddlSoTypeOper.SelectedValue);
                }
                return "";
            }
        }

        public string OwnerID
        {
            get
            {
                if (!string.IsNullOrEmpty(this.txtOwnerID.Text.Trim()))
                {
                    return base.GetParamsString(this.txtOwnerID.Text.Trim(), this.ddlOwnerIDOper.SelectedValue);
                }
                return "";
            }
        }

        public string SoDate
        {
            get
            {
                if (!string.IsNullOrEmpty(this.txtSoDate.Text.Trim()))
                {
                    return base.GetParamsString(this.txtSoDate.Text.Trim(), this.ddlSoDateOper.SelectedValue, this.txtSoDate2.Text.Trim(), "SoDate");
                }
                return "";
            }
        }

        public string SoID
        {
            get
            {
                if (!string.IsNullOrEmpty(this.txtSoID.Text.Trim()))
                {
                    return base.GetParamsString(this.txtSoID.Text.Trim(), this.ddlSoIDOper.SelectedValue);
                }
                return "";
            }
        }
    }
}

